package service

import (
	"net/http"
	"strconv"

	"gitee.com/wangshh_123/cross-pay-go/src/utils/common"
	"github.com/gin-gonic/gin"
)

// GetCurrentUserID 获取当前用户ID
func GetCurrentUserID(ctx *gin.Context) (int64, bool) {
	userID, exists := ctx.Get("user_id")
	if !exists {
		common.Error(ctx, http.StatusUnauthorized, "unauthorized", nil)
		return 0, false
	}
	return userID.(int64), true
}

// ParsePathID 解析路径参数ID
func ParsePathID(ctx *gin.Context, paramName string) (int64, bool) {
	id, err := strconv.ParseInt(ctx.Param(paramName), 10, 64)
	if err != nil {
		common.Error(ctx, http.StatusBadRequest, "invalid_id", err)
		return 0, false
	}
	return id, true
}

// GetPaginationParams 获取分页参数
func GetPaginationParams(ctx *gin.Context) (int, int) {
	page64, pageSize64 := common.GetPaginationParams(ctx)
	return int(page64), int(pageSize64)
}
